<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitereview
 * @copyright  Copyright 2012-2013 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: _DashboardNavigation.tpl 6590 2013-04-01 00:00:00Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
 ?>

<?php
$this->headLink()
        ->prependStylesheet($this->layout()->staticBaseUrl . 'application/modules/Sitereview/externals/styles/style_sitereview.css') ->prependStylesheet($this->layout()->staticBaseUrl . 'application/modules/Sitereview/externals/styles/style_sitereview_dashboard.css');
  $this->headScript()
    ->appendFile($this->layout()->staticBaseUrl. 'externals/moolasso/Lasso.js')
    ->appendFile($this->layout()->staticBaseUrl. 'externals/moolasso/Lasso.Crop.js')
?>

<?php
$sitereview = $this->sitereview;
$viewer = Engine_Api::_()->user()->getViewer();
$this->listingtype_id = $listingtype_id = Zend_Controller_Front::getInstance()->getRequest()->getParam('listingtype_id', null);
Engine_Api::_()->sitereview()->setListingTypeInRegistry($listingtype_id);
$listingType = Zend_Registry::get('listingtypeArray' . $listingtype_id);
$listing_singular_upper = strtoupper($listingType->title_singular);

$allowStyle = Engine_Api::_()->getDbtable('permissions', 'authorization')->getAllowed('sitereview_listing', $viewer->level_id, "style_listtype_$listingtype_id");

$allowOverview = Engine_Api::_()->authorization()->getPermission($viewer->level_id, 'sitereview_listing', "overview_listtype_$listingtype_id");

$allowCreation = Engine_Api::_()->authorization()->getPermission($viewer->level_id, 'sitereview_listing', "create_listtype_$listingtype_id");

$allowEdit = $this->sitereview->authorization()->isAllowed($viewer, 'edit_listtype_' . $sitereview->listingtype_id);

$allowVideoUpload = Engine_Api::_()->sitereview()->allowVideo($this->sitereview, $viewer);
$allowPhotoUpload = Engine_Api::_()->authorization()->isAllowed($this->sitereview, $viewer, "photo_listtype_$listingtype_id");

$allowContactDetailsUpload = Engine_Api::_()->authorization()->getPermission($viewer->level_id, 'sitereview_listing', "contact_listtype_$listingtype_id");

$allowMetaKeywords = Engine_Api::_()->authorization()->getPermission($viewer->level_id, 'sitereview_listing', "metakeyword_listtype_$listingtype_id");

$this->title = ucfirst($listingType->title_plural);
$params['listing_type_title'] = $this->title;
$params['dashboard'] = $this->translate('Dashboard');
//SET META TITLE
Engine_Api::_()->sitereview()->setMetaTitles($params);

$this->navigation = Engine_Api::_()->getApi('menus', 'core')->getNavigation("sitereview_main_listtype_$listingtype_id");
include_once APPLICATION_PATH . '/application/modules/Sitereview/views/scripts/navigation_views.tpl';
?>
<div class='seaocore_db_tabs'>
  <ul>
    <?php if (!empty($allowEdit)): ?>
      <li>
				<?php $url = $this->url(array('action' => 'edit', 'listing_id' => $this->sitereview->listing_id), "sitereview_specific_listtype_$listingtype_id", true); ?>
        <a class="<?php echo ($this->TabActive == "edit") ? 'selected' : '' ?>" href='<?php echo $this->url(array('action' => 'edit', 'listing_id' => $this->sitereview->listing_id), "sitereview_specific_listtype_$listingtype_id", true) ?>' ><?php echo $this->translate('Edit Info'); ?></a>
      </li>
      
      <?php if ($allowOverview && !empty($listingType->overview)): ?>
        <li>
          <a class="<?php echo ($this->TabActive == "overview") ? 'selected' : '' ?>" href='<?php echo $this->url(array('action' => 'overview', 'listing_id' => $this->sitereview->listing_id), "sitereview_specific_listtype_$listingtype_id", true) ?>' ><?php echo $this->translate("DASHBOARD_".$listing_singular_upper."_OVERVIEW"); ?></a>
        </li>
      <?php endif; ?>      

     <?php if (!empty($allowPhotoUpload) && ($listingType->photo_type == 'listing')): ?>
      <li>
				<?php $url = $this->url(array('action' => 'change-photo', 'listing_id' => $this->sitereview->listing_id), "sitereview_dashboard_listtype_$listingtype_id", true) ?>
        <a class="<?php echo ($this->TabActive == "profilepicture") ? 'selected' : '' ?>" href='javascript:void(0);' onclick="showAjaxBasedContent('<?php echo $url;?>')" ><?php echo $this->translate('Profile Picture'); ?></a>
      </li>
      <?php endif; ?>   

      <?php if($allowContactDetailsUpload && !empty($listingType->contact_detail)):?>
        <li>

				<?php $url = $this->url(array('action' => 'contact', 'listing_id' => $this->sitereview->listing_id), "sitereview_dashboard_listtype_$listingtype_id", true) ?>

          <a class="<?php echo ($this->TabActive == "contactdetails") ? 'selected' : '' ?>" href='javascript:void(0);' onclick="showAjaxBasedContent('<?php echo $url;?>')" ><?php echo $this->translate('Contact Details'); ?></a>
        </li>
      <?php endif; ?>     
        
      <?php if (Engine_Api::_()->sitereview()->enableLocation($listingtype_id)): ?>
        <li>
          <a class="<?php echo ($this->TabActive == "location") ? 'selected' : '' ?>" href='<?php echo $this->url(array('action' => 'editlocation', 'listing_id' => $this->sitereview->listing_id), "sitereview_specific_listtype_$listingtype_id", true) ?>' ><?php echo $this->translate('Location'); ?></a>
        </li>
      <?php endif; ?>        
        
      <?php if ($allowPhotoUpload): ?>
        <li>
				  <?php $url = $this->url(array('listing_id' => $this->sitereview->listing_id), "sitereview_albumspecific_listtype_$listingtype_id", true) ?>
          <a class="<?php echo ($this->TabActive == "photo") ? 'selected' : '' ?>" href='javascript:void(0);' onclick="showAjaxBasedContent('<?php echo $url;?>')" ><?php echo $this->translate('Photos'); ?></a>
        </li>
      <?php endif; ?>

      <?php if ($allowVideoUpload): ?>
        <li>
          <?php $url = $this->url(array('listing_id' => $this->sitereview->listing_id), "sitereview_videospecific_listtype_$listingtype_id", true) ?>
          <a class="<?php echo ($this->TabActive == "video") ? 'selected' : '' ?>" href='javascript:void(0);' onclick="showAjaxBasedContent('<?php echo $url;?>')" ><?php echo $this->translate('Videos'); ?></a>
        </li>
      <?php endif; ?>     
        
      <?php if ($listingType->where_to_buy): ?>
        <li>

					<?php $url = $this->url(array('id' => $this->sitereview->listing_id), "sitereview_priceinfo_listtype_$listingtype_id", true) ?>
          <a class="<?php echo ($this->TabActive == "priceinfo") ? 'selected' : '' ?>" href='javascript:void(0);' onclick="showAjaxBasedContent('<?php echo $url;?>')" ><?php echo $this->translate("DASHBOARD_".$listing_singular_upper."_WHERE_TO_BUY"); ?></a>
        </li>
      <?php endif; ?>        
        
      <?php if($allowMetaKeywords && !empty($listingType->metakeyword)):?>
        <li>
					<?php $url = $this->url(array('action' => 'meta-detail', 'listing_id' => $this->sitereview->listing_id), "sitereview_dashboard_listtype_$listingtype_id", true) ?>
          <a class="<?php echo ($this->TabActive == "metadetails") ? 'selected' : '' ?>" href='javascript:void(0);' onclick="showAjaxBasedContent('<?php echo $url;?>')" ><?php echo $this->translate('Meta Keywords'); ?></a>
        </li>
      <?php endif; ?>

      <?php if ($allowStyle): ?>
        <li>
					<?php $url = $this->url(array('action' => 'editstyle', 'listing_id' => $this->sitereview->listing_id), "sitereview_specific_listtype_$listingtype_id", true) ?>
          <a class="<?php echo ($this->TabActive == "style") ? 'selected' : '' ?>" href='javascript:void(0);' onclick="showAjaxBasedContent('<?php echo $url;?>')" ><?php echo $this->translate('Edit Style'); ?></a>
        </li>
      <?php endif; ?>        
    <?php endif; ?>
  </ul>
  
  <div class="sr_dashboard_info clr">
    <div class="sr_dashboard_info_image prelative">
			<?php if($this->sitereview->newlabel):?>
				<i class="sr_list_new_label" title="<?php echo $this->translate('New'); ?>"></i>
			<?php endif;?>
      <?php echo $this->htmlLink($this->sitereview->getHref(array('profile_link' => 1)), $this->itemPhoto($this->sitereview, 'thumb.profile')) ?>
    </div>
    <center class="clr">
      <span>
        <?php if ($this->sitereview->sponsored == 1): ?>
          <i title="<?php echo $this->translate('Sponsored');?>" class="sr_icon seaocore_icon_sponsored"></i>
        <?php endif; ?>
        <?php if ($this->sitereview->featured == 1): ?>
          <i title="<?php echo $this->translate('Featured');?>" class="sr_icon seaocore_icon_featured"></i>
        <?php endif; ?>
      </span>
    </center>
  </div> 
  
</div>

<script type="text/javascript">

	function showAjaxBasedContent(url) {
		if (history.pushState) {
			history.pushState( {}, document.title, url );
		} else {
			window.location.hash = url;
		}
		$('global_content').getElement('.sr_dashboard_content').innerHTML = '<div class="seaocore_content_loader"></div>'; 
		en4.core.request.send(new Request.HTML({
			url : url,
			'method' : 'get',
			data : {
				format : 'html',
				'isajax' : 1
			},onSuccess :  function(responseTree, responseElements, responseHTML, responseJavaScript)  {
					$('global_content').innerHTML = responseHTML;
          Smoothbox.bind($('global_content'));
          en4.core.runonce.trigger();
					if (window.InitiateAction) {
						InitiateAction ();
					}
				}
		}));
	}

var requestActive = false;
window.addEvent('load', function() {
  InitiateAction();
});

var InitiateAction = function () {
  formElement = $$('.global_form')[0];
  if (typeof formElement != 'undefined' ) {
    formElement.addEvent('submit', function(event) {
      if (typeof submitformajax != 'undefined' && submitformajax == 1) {
        submitformajax = 0;
        event.stop();
        Savevalues();
      }
    })
  }
}

var Savevalues = function() {
  if( requestActive ) return;

  requestActive = true;
  var pageurl = $('global_content').getElement('.global_form').action;
 
  currentValues = formElement.toQueryString();
  $('show_tab_content_child').innerHTML = '<div class="seaocore_content_loader"></div>';
  if (typeof page_url != 'undefined') {
    var param = (currentValues ? currentValues + '&' : '') + 'isajax=1&format=html&page_url=' + page_url;
  }
  else {
    var param = (currentValues ? currentValues + '&' : '') + 'isajax=1&format=html';
  }

  var request = new Request.HTML({
    url: pageurl,
    onSuccess :  function(responseTree, responseElements, responseHTML, responseJavaScript)  {
      $('global_content').innerHTML =responseHTML;
      InitiateAction (); 
      requestActive = false;
    }
  });
  request.send(param);
}

</script>